﻿//------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2020年1月5日 20:53:43
//------------------------------------------------------------

using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace NKG_MVVM_UI
{
    public abstract class AState
    {
        public Dictionary<string, PropertyInfo> PropertyInfos = new Dictionary<string, PropertyInfo>();

        public AState()
        {
            var t = GetType();
            var list = new List<PropertyInfo>();
            list.AddRange(t.GetProperties());
            foreach (var mi in list)
            {
                PropertyInfos[mi.Name] = mi;
            }
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            foreach (var VARIABLE in PropertyInfos)
            {
                sb.Append($"{VARIABLE.Key}:{VARIABLE.Value.GetValue(this)},");
            }

            return sb.ToString();
        }

        public T ShadowClone<T>() where T :AState
        {
            return (T)MemberwiseClone();
        }
    }
}